from uuid import uuid4
from django.contrib.auth import get_user_model
from django.db import models

User = get_user_model()


class BaseModel(models.Model):
    # 基础的base model
    id = models.UUIDField(verbose_name='id', default=uuid4, primary_key=True)
    created_at = models.DateTimeField(verbose_name='创建时间', auto_now_add=True, null=True)
    created_by = models.ForeignKey(User, verbose_name='创建人', on_delete=models.SET_NULL, null=True,
                                   related_name='%(class)s_created', related_query_name='%(class)s_created_query',
                                   editable=False)
    modified_at = models.DateTimeField(verbose_name='修改时间', auto_now=True, null=True)
    modified_by = models.ForeignKey(User, verbose_name='修改人', on_delete=models.SET_NULL, null=True,
                                    related_name='%(class)s_modified', related_query_name='%(class)s_modified_query',
                                    editable=False)

    class Meta:
        abstract = True
